﻿

using System.Linq;
using System.Linq.Expressions;

namespace Main.Repository
{
    public interface IRepository<T> where T : class, new()
    {
        /// <summary>
        /// 根据主键查找
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="Id"></param>
        /// <returns></returns>
        T Find(dynamic Id);

        /// <summary>
        /// 添加一个
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="t"></param>
        /// <returns></returns>
        bool Add(T t);
        Task<bool> AddAsync(T t);

        /// <summary>
        /// 添加多个
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="t"></param>
        /// <returns></returns>
        bool AddRange(IEnumerable<T> t);

        Task<bool> AddRangeAsync(IEnumerable<T> t);
        /// <summary>
        /// 删除一个
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="t"></param>
        /// <returns></returns>
        bool Delete(T t);
        Task<bool> DeleteAsync(T t);
        /// <summary>
        /// 删除多个
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="t"></param>
        /// <returns></returns>
        bool DeleteRange(IEnumerable<T> t);
        Task<bool> DeleteRangeAsync(IEnumerable<T> t);
        /// <summary>
        /// 修改一个
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="t"></param>
        /// <returns></returns>
        bool Update(T t);
        Task<bool> UpdateAsync(T t);
        /// <summary>
        /// 修改多个
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="t"></param>
        /// <returns></returns>
        bool UpdateRange(IEnumerable<T> t);
        Task<bool> UpdateRangeAsync(IEnumerable<T> t);

        bool UpdateWhere(Expression<Func<T, bool>> WhereLambda, Func<T, T> UpdateLambda);
        Task<bool> UpdateWhereAsync(Expression<Func<T, bool>> WhereLambda, Func<T, T> UpdateLambda);

        IQueryable<T> QueryAll(Expression<Func<T, bool>>? where);
        /// <summary>
        /// 查询所有 条件数组
        /// </summary>
        /// <param name="wheres"></param>
        /// <returns></returns>
        IQueryable<T> QueryAll(params Expression<Func<T, bool>>[] wheres);

        /// <summary>
        /// 查询所有 后排序 IEnumerable
        /// </summary>
        /// <typeparam name="type">排序字段类型</typeparam>
        /// <param name="order">排序参数 lambda 表达式</param>
        /// <param name="isAsc">升序 or 降序 true 升序 false 降序</param>
        /// <param name="wheres">查询条件 多个</param>
        /// <returns></returns>
        IQueryable<T> QueryAll<type>(Expression<Func<T, type>> order, bool isAsc = true, Expression<Func<T, bool>>? where = null);

        /// <summary>
        /// 查询分页 并排序 params []
        /// </summary>
        /// <typeparam name="type">排序字段类型</typeparam>
        /// <param name="total">总条数</param>
        /// <param name="skip">跳过多少条</param>
        /// <param name="take">取多少条</param>
        /// <param name="order">排序条件</param>
        /// <param name="isAce">排序方法</param>
        /// <param name="wheres">查询条件</param>
        /// <returns></returns>
        IQueryable<T> QueryAll<type>(out int total, int skip, int take, Expression<Func<T, type>> order, bool isAce = true, Expression<Func<T, bool>>? where = null);
    }
}
